const {CreateOrder,findAllOrder,updateOrder}=require('../service/orders.service')
class OrdersController{
    async addOrdersFun(ctx){
        const user_id=ctx.state.user.id
        const {address_id,goods_info,total,status}=ctx.request.body
        const order_num='bs'+Date.now()
        const res=await CreateOrder({
            user_id,address_id,goods_info,total,order_num,status
        })
        ctx.body={
            message:"生成订单",
            result:res
        }
    }
    async getOrderAll(ctx){
        const user_id=ctx.state.user.id
        const {status}=ctx.request.query
        const res=await findAllOrder(status,user_id)
        ctx.body={
            code:0,
            message: "获取订单列表成功",
            result: res
        }

    }
    async update(ctx){
        const id=ctx.request.params.id
        const {status}=ctx.request.body
        const res=await updateOrder(id,status)
        ctx.body={
            message:"修改订单成功",
            res:res
        }
    }
}
module.exports=new OrdersController()